import { Page, PageSearch } from '@2/typings/page';
import { Result } from '@2/typings/http.d';
import { defHttp } from '@/utils/http/axios';
import { filterObj } from '@2/app/core/utils/base.util';
import { ApiBase } from '@2/app/core/api/api.base';
import { injectable } from 'inversify';

/**
 * @program: microservice-central-portal
 * @description: 系统基本业务接口实现
 * @author: baiHoo.chen
 * @create: 2024-04-07
 **/
@injectable()
export abstract class ApiBaseImpl<T> implements ApiBase<T> {
  abstract listUrl: string;
  queryPageList(pageSearch: PageSearch): Promise<Result<Page<T[]>>> {
    const param: { [key: string]: string } = Object.assign(pageSearch.queryParam, pageSearch.sort);
    param.pageNo = String(pageSearch.page);
    param.pageSize = String(pageSearch.pageSize);
    return defHttp.get<Result<Page<T[]>>>({
      url: this.listUrl,
      params: filterObj(param),
    });
  }
}
